package com.shenfc.fxzj.action.admin;


import com.shenfc.fxzj.domain.SysMenu;
import com.shenfc.fxzj.domain.SysMenuBtn;
import com.shenfc.fxzj.service.ISysMenuBtnService;
import com.shenfc.fxzj.service.ISysMenuService;
import com.shenfc.fxzj.solr.BlogSolrIndex;
import com.shenfc.fxzj.util.HtmlUtil;
import com.shenfc.fxzj.util.TreeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 管理员博客Controller层
 *
 * @author Administrator
 */
@Controller
@RequestMapping("/admin/sysMenu")
public class SysMenuAdminAction extends BaseAction {

    @Autowired
    private ISysMenuService sysMenuService;
    @Autowired
    private ISysMenuBtnService sysMenuBtnService;

    // 博客索引
    private BlogSolrIndex blogIndex = new BlogSolrIndex();

    private static String content;

    private final static Logger log = LoggerFactory.getLogger(SysMenuAdminAction.class);

    @RequestMapping("/index")
    public ModelAndView index() throws Exception {
        return new ModelAndView("admin/sysMenu/sysMenuList");
    }

//    @RequestMapping("/list")
//    public void list(PageBean pageBean, SysMenu sysMenu, HttpServletResponse response) {
//        DataGridJson<Blog> dataGridJson = new DataGridJson<Blog>();
//        try {
//            Map<String, Object> map = new HashMap<String, Object>();
//            map.put("title", blog.getTitle());
//            PageInfo<Blog> pageInfo = blogService.queryBlogPage(map, pageBean);
//            List<Blog> blogList = pageInfo.getList();
//            dataGridJson.setData(blogList);
//            dataGridJson.setCount(pageBean.getRecTotal());
//            HtmlUtil.writerJson(response, dataGridJson);
//        } catch (Exception e) {
//            dataGridJson.setCode(1);
//            dataGridJson.setMsg("请求出现异常，请联系管理员！");
//            HtmlUtil.writerJson(response, dataGridJson);
//        }
//    }

    @RequestMapping("/getMenuTree")
    public void getMenuTree(Integer id, HttpServletResponse response) throws Exception {
        List<SysMenuBtn> sysMenuBtnList = sysMenuBtnService.getAllSysMenuBtns();
        List<SysMenu> sysMenuList = sysMenuService.getAllSysMenus();//所有节点
        TreeUtil util = new TreeUtil(sysMenuList, sysMenuBtnList);
        HtmlUtil.writerJson(response, util.getRootNodes());
    }
}
